var INFO;
$(document).ready(function(){                   //表格里的内容
  $("#SearchSubmit").click(function(){
    $.post("fourth_page_courses_info.php",{
      cname:$("#cname").val(),
      cid:$("#cid").val()
    },function(data){
      var obj = eval("("+data+")");
      INFO = obj;
      $.each(obj,function(key,value){
        $("#table_student_info").append("<tr>"+
      "<th>"+value.cid+"</th>"+
      "<th>"+value.cname+"</th>"+
      "<th>"+value.teacher+"</th>"+
      "<th>"+value.point+"</th>"+
      "<th>"+value.adapt_grade+"</th>"+
      "<th>"+value.cancel_year+"</th>"+
      "<th>"+"<button onclick=change("+key+") id='"+value.cid+"'>选课</button>"+"</th>"+
      "</tr>");


      });
    });

  });
});




var times_of_click_change = 0;

function change(key){           //修改内容
  $("#ChangeSubmit").attr("data-key",key);
  times_of_click_change++;
  if(times_of_click_change %2 == 1)
  show();
  else
  hidden();
}

function show(){          //显示
document.getElementById("change_course_select_info").style.display="block";
//alert(document.getElementById("div").style.display)
}
function hidden(){         //隐藏
document.getElementById("change_course_select_info").style.display="none";
//alert(document.getElementById("div").style.display)
}



$(document).ready(function(){                   //修改内容
  $("#ChangeSubmit").click(function(e){
    //console.log(INFO[e.target.dataset.key]);
    //console.log(INFO[e.target.dataset.key]);
    $.post("fourth_page_courses_select.php",{
      cname:INFO[e.target.dataset.key].cname,
      cid:INFO[e.target.dataset.key].cid,
      sid:$("#sid").val()
    },function(data){
     alert(data);
    });

  });
});




var deleteInfo;

$(document).ready(function(){                   //表格里的内容
  $("#SearchSubmit").click(function(e){
     //console.log(deleteInfo[e.target.dataset.key]);
    $.post("fourth_page_students_info.php",{
      cname:$("#cname").val(),
      cid:$("#cid").val()
    },function(data){
      var obj = eval("("+data+")");
      deleteInfo=obj;
      $.each(obj,function(key,value){


      $("#table_course_students_info").append("<tr>"+
      "<th>"+value.name+"</th>"+
      "<th>"+value.sid+"</th>"+
      "<th>"+value.gender+"</th>"+
      "<th>"+value.enrolled_age+"</th>"+
      "<th>"+value.enrolled_year+"</th>"+
      "<th>"+value.score+"</th>"+
      "<th>"+"<button onclick=deleteCourse("+key+")>退课</button>"+"</th>"+
      "</tr>");


      });
    });

  });
});


function deleteCourse(key){           //退课
  console.log(deleteInfo[key]);
  $.post("fourth_page_courses_select_info_delete.php",{
      cname:deleteInfo[key].cname,
      cid:deleteInfo[key].cid,
      sid:deleteInfo[key].sid
    },function(data){
      alert(data);
    });
}



// var times_of_click_change = 0;

// function change_score(){           //修改
//   times_of_click_change++;
//   if(times_of_click_change %2 == 1)
//   show();
//   else
//   hidden();
// }

// function show(){          //显示
// document.getElementById("change_student_score").style.display="block";
// //alert(document.getElementById("div").style.display)
// }
// function hidden(){         //隐藏
// document.getElementById("change_student_score").style.display="none";
// //alert(document.getElementById("div").style.display)
// }

// $(document).ready(function(){                   //修改内容
//   $("#ChangeSubmit").click(function(){
//     $.post("fourth_page_change_score.php",{
//       cname:$("#cname").val(),
//       cid:$("#cid").val(),
//       score:$("#score").val()
//     },function(data){
//      alert(data);
//     });

//   });
// });
